package testClasses;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

import org.sparx.Repository;

import utils.ControllerUtils;

public class UtilitiesTest {

	/**
	 * tesing xpath function through the packages
	 * 
	 * @param EAFilePath
	 * @param xPath
	 */
	public void test1(String EAFilePath, String xPath) {
		Repository rep = ControllerUtils.connectEA(EAFilePath);
		org.sparx.Package targetPack = ControllerUtils.XPath(rep, xPath);
		if (targetPack != null) {
			System.out.println("the name of Package is: "
					+ targetPack.GetName());
			System.out.println("the notes to package is: "
					+ targetPack.GetNotes());

		}
		ControllerUtils.disconnectEA(rep);
	}

	/**
	 * testing clear function
	 * 
	 * @param EAFilePath
	 * @param XPath
	 */

	public void test2(String EAFilePath, String XPath) {
		Repository rep = ControllerUtils.connectEA(EAFilePath);
		org.sparx.Package pak = ControllerUtils.XPath(rep, XPath);
		ControllerUtils.clearAllElements(pak);
		ControllerUtils.disconnectEA(rep);
	}

	/**
	 * testing property reader writer utility
	 */
	public void test3() {
		try {
			Properties prop = new Properties();
			prop.put("#cd",
					"utils.ControllerUtils.xpath(org.sparx.Repositary,String)");
			prop.storeToXML(
					new FileOutputStream(new File("config/mapping.xml")), "");
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public static void main(String[] args) {
		/*
		 * new UtilitiesTest().test1(System.getProperty("user.dir") +
		 * "/DATA/PSLIntAAS.eap", "Release 13B/Document Model/TDs/"); / new
		 * UtilitiesTest().test2(System.getProperty("user.dir") +
		 * "/DATA/PSLIntAAS.eap", "Release 13B/Document Model/TDs/");
		 */
		new UtilitiesTest().test3();
	}
};
